import { defineStore } from "pinia";
import { ref } from "vue";

// export const useCounterStore = defineStore({
//   id: "counter",
//   state: () => ({
//     counter: 0,
//   }),
//   getters: {
//     doubleCount: (state) => state.counter * 2,
//   },
//   actions: {
//     increment() {
//       this.counter++;
//     },
//   },
// });

// 保存用户状态的一个Store
export const useUserStore = defineStore(
  "user",
  () => {
    const username = ref("");
    const password = ref("");
    function login(user, pass) {
      username.value = user;
      password.value = pass;
    }

    return { username, password, login };
  },
  // 通过额外的options, 开启持久化的支持(pinia-plugin-persist插件的参数)
  {
    persist: {
      enabled: true,
      strategies: [{ storage: localStorage, paths: ["username", "password"] }],
    },
  }
);
